<template>
  <list-condition-template
    ref="table"
    :rows="rows"
    :defaultSort="{ prop: 'createTime', order: 'descending' }"
    :total="total"
    @page-info-change="handlePageInfoChange"
    :search-data="listQuery"
    :batch-column="false"
  >
    <template slot="condition">
      <el-tabs
        v-model="listQuery.type"
        @tab-click="orderStateChange"
      >
        <el-tab-pane
          label="全部"
          :name="null"
        ></el-tab-pane>
        <el-tab-pane
          v-for="(item, key) in $CONST.AMOUNT_CHANGE_TYPE"
          :key="key"
          :label="item.title"
          :name="item.name"
        ></el-tab-pane>
      </el-tabs>

      <el-form-item prop="keyword">
        <el-input
          placeholder="关键词"
          v-model="listQuery.keyword"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item prop="dateArray">
        <el-date-picker
          v-model="listQuery.dateArray"
          type="daterange"
          range-separator="~"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="center"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
    </template>
    <template slot="columns">
      <el-table-column
        label="变动金额（元）"
        align="center"
        property="amount"
      ></el-table-column>
      <el-table-column
        label="类型"
        align="center"
      >
        <template slot-scope="scope">
          <template v-if="scope.row.type.name === 'Recharge' || scope.row.type.name === 'Other'">{{ scope.row.type.desc }}</template>
          <template v-if="scope.row.type.name === 'Consume' || scope.row.type.name === 'Return'">
            <el-link type="primary" @click="showOrderDetail(scope.row)">{{ scope.row.type.desc }}</el-link>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        label="支付方式"
        align="center"
      >
        <template slot-scope="scope">
          <template v-if="scope.row.payType">
            {{ scope.row.payType.desc }}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        min-width="150"
        align="center"
        property="remark"
      ></el-table-column>
      <!-- <el-table-column
        label="充值状态"
        align="center"
      >
        <template slot-scope="scope">
          {{scope.row.finish?'完成':'未完成'}}
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作时间"
        align="center"
        property="createTime"
      ></el-table-column>
      <!-- <el-table-column
        align="center"
        label="详情"
        class-name="fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="showDetail(scope.row)"
            v-waves
            >查看</el-button
          >
        </template>
      </el-table-column>-->
    </template>
  </list-condition-template>
</template>

<script>
import AmountChangeLogApi from '@/api/amountChangeLog'
import waves from '@/directive/waves' // 水波纹指令
import ListConditionTemplate from '@/components/templates/listConditionTemplate'

export default {
  directives: {
    waves
  },
  components: {
    ListConditionTemplate
  },
  data () {
    return {
      selectLoading: false,
      rows: [],
      total: 0,
      dateArray: [],
      listQuery: {},
      studios: []
    }
  },
  methods: {
    orderStateChange (tab, event) {
      this.handleFilter()
    },
    /**
     * 加载数据
     */
    getList (pageInfo) {
      if (
        Array.isArray(this.listQuery.dateArray) &&
        this.listQuery.dateArray.length === 2
      ) {
        this.listQuery.startTime = this.listQuery.dateArray[0] + ' 00:00:00'
        this.listQuery.endTime = this.listQuery.dateArray[1] + ' 23:59:59'
      } else {
        this.listQuery.startTime = null
        this.listQuery.endTime = null
      }
      AmountChangeLogApi.getPaged({ condition: this.listQuery, pageInfo }).then(
        (response) => {
          console.log('res', response)

          this.rows = response.data.content
          this.total = response.data.totalElements
        }
      )
    },
    /**
     * 搜索条件变更处理
     */
    handleFilter () {
      this.$refs.table.changeCondition()
    },
    /**
     * 分页信息变动事件处理
     * @param  {Object} pageInfo 分页信息
     */
    handlePageInfoChange (pageInfo) {
      this.getList(pageInfo)
    },
    /**
     * 查看订单详情点击处理
     * @param {*} row 参数
     */
    showOrderDetail (row) {
      this.$router.pushTo(this.$router.routesConfig.orderInfo, row.targetId)
    },
    /**
     * 查看详情点击处理
     * @param {*} row 参数
     */
    showDetail (row) {
      this.$router.pushTo(this.$router.routesConfig.orderInfo, row.id)
    }
  }
}
</script>
<style lang="scss">
.condition {
  margin-right: 10px;
}
</style>
